﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverlightClientLibrary.Clients;
using SilverlightClientLibrary.Messages;
using System.Windows.Threading;

namespace SilverlightUdpClient
{
    public partial class MainPage : UserControl
    {
        private SilverlightClientLibrary.Clients.SilverlightUdpClient _client;
        private DispatcherTimer _dt;

        public MainPage()
        {
            InitializeComponent();

            _dt = new DispatcherTimer();
            _dt.Interval = TimeSpan.FromSeconds(3);
            _dt.Tick += new EventHandler(_dt_Tick);
            _dt.Start();

            _client = new SilverlightClientLibrary.Clients.SilverlightUdpClient(App.Current, EndJoinGroup, EndSendMessage, MessageReceived, PointMessageReceived);
        }

        void _dt_Tick(object sender, EventArgs e)
        {
            //_client.BeginSendMessage(new BlankMessage());
        }

        private void EndJoinGroup(bool joined)
        {
            this.silverlightMessageWindow1.AddMessage("Group joined!");
        }

        private void EndSendMessage()
        {

        }

        private void PointMessageReceived(PointMessage pm)
        {

        }

        private void MessageReceived(IPEndPoint ip)
        {
            this.silverlightMessageWindow1.AddMessage(ip.ToString());
        }
    }
}
